package com.plian.system.service.hr.staff.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.plian.Tools.CollectionUtil;
import com.plian.system.entity.hr.staff.AppointRemove;
import com.plian.system.mapper.hr.staff.AppointRemoveMapper;
import com.plian.system.mybatis.base.BaseServiceImpl;
import com.plian.system.service.hr.staff.IAppointRemoveService;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * 任免记录 服务实现类
 *
 * @author gangan
 * @since 2019-09-30
 */
@Service
@AllArgsConstructor
public class AppointRemoveServiceImpl extends BaseServiceImpl<AppointRemoveMapper, AppointRemove> implements IAppointRemoveService {

	@Override
	public List<AppointRemove> ListByPid(Long pid) {
		return list(new LambdaQueryWrapper<AppointRemove>().eq(AppointRemove::getIsDeleted, 0).eq(AppointRemove::getStaffFilesId, pid));
	}

	@Override
	public Boolean deleteLogicStaffFilesId(List<Long> ids) {
		LambdaQueryWrapper<AppointRemove> queryWrapper = new LambdaQueryWrapper<>();
		queryWrapper.in(AppointRemove::getStaffFilesId, ids);
		List<AppointRemove> appointRemoves = list(queryWrapper);
		if (CollectionUtil.isNotEmpty(appointRemoves)){
			return deleteLogic(appointRemoves.stream().map(AppointRemove::getId).collect(Collectors.toList()));
		}
		return true;
	}
}
